USE [ServerMonitor]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DBUsage_Server]') AND parent_object_id = OBJECT_ID(N'[dbo].[DBUsage]'))
ALTER TABLE [dbo].[DBUsage] DROP CONSTRAINT [FK_DBUsage_Server]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_DBUsage_RecordTime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[DBUsage] DROP CONSTRAINT [DF_DBUsage_RecordTime]
END
GO
USE [ServerMonitor]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DBUsage]') AND type in (N'U'))
DROP TABLE [dbo].[DBUsage]
GO
USE [ServerMonitor]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DBUsage](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[DBName] [nvarchar](256) NOT NULL,
	[ServerId] [smallint] NOT NULL,
	[DataSize] [int] NOT NULL,
	[DataUsage] [int] NOT NULL,
	[LogSize] [int] NOT NULL,
	[LogUsage] [int] NOT NULL,
	[RecordTime] [datetime] NOT NULL,
 CONSTRAINT [PK_DBUsage] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[DBUsage]  WITH CHECK ADD  CONSTRAINT [FK_DBUsage_Server] FOREIGN KEY([ServerId])
REFERENCES [dbo].[Server] ([Id])
GO

ALTER TABLE [dbo].[DBUsage] CHECK CONSTRAINT [FK_DBUsage_Server]
GO

ALTER TABLE [dbo].[DBUsage] ADD  CONSTRAINT [DF_DBUsage_RecordTime]  DEFAULT (getdate()) FOR [RecordTime]
GO


